/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package html_parse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 *
 * @author khanhvv
 */
public class HTML_Parse {

    /**
     * @param args the command line arguments
     */

   public void k() throws IOException
   {
       // TODO code application logic here
             String url="http://www.7giftshop.com/qua-tang/thu-nhoi-bong.html"+"?limit=all";
;
        func_My themProduct=new func_My("root", "12345678", "");
      //  themProduct.func_Insert_Product(1, 1, "21212", "21212", "22222222","22222222","eeeeee", "eeeee", Float.valueOf(1),Float.valueOf(1));
       // themProduct.func_Insert_ImageSP(1, "Dddđ", "ddddđ");
        Document doc=Jsoup.connect(url).timeout(10000).get()  ; 
     
       
        
       
        Elements link=doc.getElementsByClass("item");
        int i=0;
        for(Element src: link)
        {
            
     
     // Lấy tên Sản Phẩm
       String TenSanPham= src.getElementsByClass("product-name").text();
            
           //Lây duong dan anh
         String DuongDanAnh=   src.getElementsByTag("img").attr("abs:src");            
           
            
            i++;
             
             String giaGoc="", giaKM="";
             //gia san pham
             int k=0;
            for(Element price :src.getElementsByClass("price"))
            {
               String te= price.text();
                if(k==0) 
                {
                    giaGoc= te.substring(0,te.length()-5).replace(".", "");
                    giaKM="0";
                }
                else giaKM=te.substring(0,te.length()-5).replace(".", "");
                k++;
            }
           
             
             // lay thong tin nhanh va thong tin chi tiet
            String ThongTinNhanh="",ThongTinChiTiet="",Duongdan=src.getElementsByClass("product-image").attr("href");
           Document doc1=Jsoup.connect(Duongdan).timeout(100000).get()  ;
             int j=0;
             for(Element dscrip:doc1.getElementsByClass("std"))
             {
                 if(j==0)
                    ThongTinNhanh= dscrip.text();
                 else
                     ThongTinChiTiet=dscrip.text();
                 j++;
             }
               
        themProduct.func_Insert_Product(1, 11,TenSanPham,Duongdan,DuongDanAnh,"", ThongTinNhanh, ThongTinChiTiet,Float.valueOf(giaGoc), Float.valueOf(giaKM));
          System.out.print(i+"   "+TenSanPham+"\n"); 

  
   

   }
   }
    /**
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        func_My my_SQL=new func_My("root", "12345678", "");
        ArrayList<Product> listProduct=my_SQL.func_GetProduct(1, 1);
        for(int i=0;i<listProduct.size();i++)
        {
            my_SQL.funf_Insert_Image_SP(listProduct.get(i).getLinkChiTiet(), listProduct.get(i).getID());
        }
    }

   
}

